package perfect

import (
	"errors"
	"math"
)

const testVersion = 1

var ErrOnlyPositive = errors.New("ErrOnlyPositive")

type Classification struct{}

var ClassificationPerfect = Classification{}
var ClassificationAbundant = Classification{}
var ClassificationDeficient = Classification{}

func Classify(input uint64) (cat Classification, err error) {

	if input <= 0 {
		err = ErrOnlyPositive
		return
	}

	square := uint64(math.Pow(float64(input), 0.5))

	sum := uint64(1)
	for i := uint64(2); i <= square; i++ {
		if input%i == 0 {
			sum += i + input/i
		}
	}

	switch {
	case sum == input:
		cat = ClassificationPerfect
	case sum > input:
		cat = ClassificationAbundant
	case sum < input:
		cat = ClassificationDeficient
	}

	return
}
